//
//  TSCityCommentPresenter.m
//  TaShuo
//
//  Created by N-X on 2018/1/17.
//  Copyright © 2018年 MRNAN. All rights reserved.
//

#import "TSCityCommentPresenter.h"
#import "TSCityCommentModel.h"
#import "SudokuCaculator.h"
static CGFloat const margin = 5;

@interface TSCityCommentPresenter()
@property (nonatomic ,strong)TSCityCommentModel * model;
@end
@implementation TSCityCommentPresenter
+ (instancetype)instanceWithCommentModel:(TSCityCommentModel *)model
{
    TSCityCommentPresenter * presenter = [[TSCityCommentPresenter alloc]init];
    presenter.model = model;
    return presenter;
}

#pragma mark - getter

- (CGFloat)cellHeight
{
    if (_cellHeight) {
        return _cellHeight;
    }
    
    // 计算(这里先计算出除了中间图片之外的所有的高度，然后在cell设置presenter 的时候再加上中间图片的高度)
    CGFloat cellH = 0;
    cellH += 55.5; // content上面控件的高度和margin是47
    //动态计算content的高度
    CGFloat contentW = [UIScreen mainScreen].bounds.size.width - 92;
    CGRect textRect = [self.model.descriptionStr boundingRectWithSize:CGSizeMake(contentW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : [UIFont fontWithName:@"PingFangSC-Regular" size:13]} context:nil];
    CGFloat contentHeight = textRect.size.height;
    cellH += contentHeight;
    cellH += margin;
    //根据SDWeiXinPhotoContainerView里面的九宫格算法，计算出middle的高度
    CGSize size = [[SudokuCaculator shareInstance] caculatorSizeWithPicArray:self.images containerWidth:KScreenWidth - 82 isJustCaculator:YES];
    self.middleHeight = size.height;
    cellH += size.height;
    //加上content底部的margin和bottom控件和bottom底部margin的高度
    cellH += 47;
    
    // 背景图片和背景View 的上下都有间距，所以这里再加上那个间距
    cellH += 10;
    return cellH;
    
}

- (NSArray *)images
{
    return self.model.imageUrlArray;
}

- (NSString *)descriptionText
{
    return self.model.descriptionStr;
}

@end
